home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
3DMAZE
/
MOVEINMA.C
< prev
next >
Wrap
Text File
|
1991-02-16
|
3KB
|
155 lines
/******************************************************
*
* MoveInMaze.c v. 1.0
* 1991 By Mark Frohnmayer
*
* NOTE - This header must appear at the beginning of all 3-D maze files!
*
* If you have any comments or recommended modifications for this code,
* email me on America On-Line at "Mark Frohn" or snail mail me at:
*
* Mark Frohnmayer
* 2875 Baker Blvd
* Eugene, OR 97403
*
* If you use this code in any program, commercial or otherwise, give
* me credit in the about box.
*
* THIS CODE MAY NOT BE SOLD OR DISTRIBUTED AT COST OR AS PART OF SOLD
* PACKAGE WITHOUT PRIOR WRITTEN CONSENT OF THE AUTHOR.
*
******************************************************/
#include "MazeData.h"
MoveForward()
{
switch(u.facing) {
case 0:
if(!maze[u.y -1][u.x])
u.y --;
break;
case 1:
if(!maze[u.y][u.x+1])
u.x ++;
break;
case 2:
if(!maze[u.y + 1][u.x])
u.y ++;
break;
case 3:
if(!maze[u.y][u.x-1])
u.x--;
break;
}
SetView();
DrawMaze();
}
TurnLeft()
{
u.facing--;
if(u.facing < 0) u.facing = 3;
SetView();
DrawMaze();
}
TurnRight()
{
u.facing++;
if(u.facing > 3) u.facing = 0;
SetView();
DrawMaze();
}
TurnAround()
{
u.facing +=2;
if(u.facing > 3) u.facing -= 4;
SetView();
DrawMaze();
}
SetView()
{
char theRows[5][4];
register int mx, my, i, j;
switch(u.facing) {
case 0:
for(j = 0; j < 2; j++) {
for(i = 0; i < 5; i++) {
mx = u.x - 2 + i;
my = u.y - 3 + j;
if(mx < 0 || mx > 15 || my < 0 || my > 15) {
uview.rows[i][j] = 0;
} else {
uview.rows[i][j] = maze[my][mx];
}
}
}
for(j = 2; j < 4; j++) {
for(i = 1; i < 4; i++) {
mx = u.x - 2 + i;
my = u.y - 3 + j;
if(mx < 0 || mx > 15 || my < 0 || my > 15) {
uview.rows[i][j] = 0;
} else {
uview.rows[i][j] = maze[my][mx];
}
}
}
break;
case 1:
for(i = 3; i > -1; i --) {
mx = u.x + i;
for(j = 0; j<5; j++) {
my = u.y - 2 + j;
if(mx < 0 || mx > 15 || my < 0 || my > 15) {
uview.rows[j][-i + 3] = 0;
} else {
uview.rows[j][-i + 3] = maze[my][mx];
}
}
}
break;
case 2:
for(j = 0; j < 4; j ++) {
my = u.y + 3 - j;
for(i = 0; i<5; i++) {
mx = u.x - 2 + i;
if(mx < 0 || mx > 15 || my < 0 || my > 15) {
uview.rows[4-i][j] = 0;
} else {
uview.rows[4-i][j] = maze[my][mx];
}
}
}
break;
case 3:
for(i = 0; i < 4; i ++) {
mx = u.x - 3 + i;
for(j = 0; j<5; j++) {
my = u.y - 2 + j;
if(mx < 0 || mx > 15 || my < 0 || my > 15) {
uview.rows[4-j][i] = 0;
} else {
uview.rows[4-j][i] = maze[my][mx];
}
}
}
break;
}
}